package com.secondhand.service.Impl;



import com.secondhand.domain.good;
import com.secondhand.domain.user;
import com.secondhand.domain.user_good;
import com.secondhand.mapper.goodMapper;
import com.secondhand.mapper.user_goodMapper;
import com.secondhand.service.goodService;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Log4j2
@Service
public class goodServiceImpl implements goodService {
    @Autowired
    goodMapper goodmapper;
    @Autowired
    user_goodMapper user_goodMapper;

    @Override
    @Transactional
    public List<good> gainGoodsList() {
        return goodmapper.selectList(null);
    }

    @Override
    public List<good> getGoodByTypeId(int typeid) {
        return goodmapper.getGoodByTypeId(typeid);
    }

    @Override
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    public Boolean addGood(good good) {
        int addgood = goodmapper.insert(good);
//        user_good usergood =new user_good();
//        usergood.setGoodId(good.getGoodId());
//        usergood.setUserId(userid);
//        int add = user_goodMapper.insert(usergood);
        return addgood!=0;
    }

    @Override
    public Boolean delGood(int goodid) {
        goodmapper.deleteGood(goodid);
        return true;
    }

    @Override
    public List<good> gainSoldGoodsList(int userId) {
        return goodmapper.gainSoldGoodsList(userId);
    }

    @Override
    public List<good> gainUnSoldGoodsList(int userId) {
        return goodmapper.gainUnSoldGoodsList(userId);
    }

    @Override
    public List<good> gainSoldingGoodsList(int userId) {
        return goodmapper.gainSoldingGoodsList(userId);
    }

    @Override
    public int updateGood(good good) {
        System.out.println("修改商品信息");
        System.out.println(good);
        int i = goodmapper.updateById(good);
        System.out.println(i);
        return i;
    }
}
